/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ca.ubc.icapture.genapha.test.tld;


import ca.ubc.icapture.genapha.beans.Login;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;


public class CheckLoginTag extends TagSupport {
       private String defaultPage = "/login.jsp";
    public int doStartTag() throws JspException {
        return (SKIP_BODY);
    }

    public int doEndTag() throws JspException {
         boolean loggedIn = false;
        HttpSession session = pageContext.getSession();
        if (Login.getLoggedIn(session)) {
            loggedIn = true;
        }

        if (loggedIn)
            return (EVAL_PAGE);
        else {
            try {
                pageContext.forward(defaultPage);
            } catch (Exception e) {
                throw new JspException(e.toString());
            }
            return (SKIP_PAGE);
        }
    }

}
